/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bbd.crawler.xml.handler;

import bbd.crawler.xml.handler.fwk.BaseXMLHandler;
import java.util.ArrayList;
import org.xml.sax.Attributes;

/**
 *
 * @author harit
 */
public class MTVServicesHandler extends BaseXMLHandler {

    private static final String TAG_NAME = "name";

    private ArrayList parsedData = null;

    private boolean startName = false;

    //--------------------------------------------------------------------------
    /** Javadoc here */
    public MTVServicesHandler() {
        setProcessorAvailable ( this.getClass().getName() );
    } // end default constructor

    //--------------------------------------------------------------------------
    /** Javadoc here */
    @Override
    public void startElement (
                    String uri,
                    String localName,
                    String qName,
                    Attributes attributes)
    {
        if ( TAG_NAME.equalsIgnoreCase (qName) ) {

            startName = true;
        }

    } // end function startElement

    //--------------------------------------------------------------------------
    /** Javadoc here */
    @Override
    public void characters (
                    char[] ch,
                    int start,
                    int length)
    {
        if ( startName ) {

            if ( parsedData == null ) {
                parsedData = new ArrayList();
            }

            parsedData.add ( 
                        new StringBuffer().append ( ch, start, length ).toString().trim()
                       );
        }

    } // end function characters

    //--------------------------------------------------------------------------
    /** Javadoc here */
    @Override
    public void endElement (
                    String uri,
                    String localName,
                    String qName)
    {
        if ( TAG_NAME.equalsIgnoreCase (qName) ) {

            dataLoaded = true;
            startName  = false;
        }

    } // end function endElement

    //--------------------------------------------------------------------------
    /** Javadoc here */
    @Override
    public Object getParsedData () {
        return parsedData;
    } // end function getParsedData

} // end class MTVServicesHandler
